package com.ytc.menu.controller;

import com.ytc.information.model.Message;
import com.ytc.information.service.InformationService;
import com.ytc.menu.model.Menu;
import com.ytc.menu.service.MenuService;
import com.ytc.pquery.model.PositionDetails;
import com.ytc.pquery.service.PqueryService;
import com.ytc.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
//菜单
@Controller
@RequestMapping("menu")
public class MenuController {

    @Autowired
    private MenuService menuService;
    @Autowired
    private InformationService informationService;
    @Autowired
    private PqueryService pqueryService;

    //获取菜单
    @RequestMapping("getMenu")
    public String getMenu(Model model, HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        System.out.println(user.getUserRole());
        Integer role = user.getUserRole();
        List<Menu> list = menuService.getMenu(role);
        System.out.println(list);
        model.addAttribute("list",list);
        return "menu/menuList";

    }

    //获取菜单
    @RequestMapping("getCenter")
    public String getCenter(Model model, HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        System.out.println(user.getUserRole());
        Integer role = user.getUserRole();
        if(role == 0){
            return "bcenter/user";
        }else {
            return "bcenter/boss";
        }
    }
    @RequestMapping("/toAccount")
    public String toAccount(Model model,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        System.out.println("账号："+user.getUserRole());
        model.addAttribute("user1",user);
        return "account/account";
    }
    @RequestMapping("/toCompany")
    public String toCompany(){
        return "company/company";
    }
    @RequestMapping("/toPosition")
    public String toPosition(){
        return "position/position";
    }
    @RequestMapping("/toPquery")
    public String toPquery(){
        return "pquery/pquery";
    }
    @RequestMapping("/toCquery")
    public String toCquery(){
        return "cquery/cquery";
    }

    @RequestMapping("toInformation")
    public String toInformation(){
        return "information/information";
    }

    @RequestMapping("toMine")
    public String toMine(){
        return "mine/mine";
    }

    //消息页面
    @RequestMapping("toMessage")
    public String toMessagge(Model model,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        List<Message> informationList = informationService.getInformationList(user.getUserId());
        model.addAttribute("list",informationList);
        return "message/message";
    }

    @RequestMapping("toSc")
    public String toSc(Model model,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        List<PositionDetails> positionDetails = pqueryService.positionLike(user.getUserId());
        model.addAttribute("list",positionDetails);
        return "mine/sc";
    }

    //应聘者页面
    @RequestMapping("toGt")
    public String toGt(Model model,HttpServletRequest request){
        User user =(User) request.getSession().getAttribute("user");
        List<Message> informationList = informationService.getInformationList1(user.getUserId());
        model.addAttribute("list",informationList);
        return "mine/gt";
    }

}
